package com.example.demo.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author ${崔灿}
 * @date 2022/12/27 18:07
 **/
@Configuration
public class ESConfig {
    //把返回的对象交予spring容器
    @Bean
    public RestHighLevelClient restHighLevelClient(){
        //String hostname, int port, String scheme
        HttpHost httpHost = new HttpHost("localhost",9200,"http");
        //HttpHost... hosts: es可能是一个集群。
        RestClientBuilder restClientBuilder= RestClient.builder(httpHost);
        RestHighLevelClient restHighLevelClient = new RestHighLevelClient(restClientBuilder);
        return restHighLevelClient;
    }
}